//package cn.java79.quiz.web;
//
//import javax.servlet.*;
//import javax.servlet.annotation.WebFilter;
//import javax.servlet.http.HttpServletRequest;
//import java.io.IOException;
//
///**
// * @author oldliu
// * @since 1.0
// */
//@WebFilter("/*")
//public class RoleFilter implements Filter {
//    @Override
//    public void init(FilterConfig filterConfig) throws ServletException {
//
//    }
//
//    @Override
//    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//        System.out.println("进入了RoleFilter");
//        HttpServletRequest request= (HttpServletRequest) servletRequest;
//        String path=request.getServletPath();
//        //无条件放行
//        if( path.equals("/resetpassEmail.jsp")|| path.equals("/studentlogin.jsp")||path.equals("/login.jsp")||path.equals("/doLogin.jsp")||path.equals("/login.stu")
//        ||path.startsWith("/js")||path.startsWith("/images")||path.endsWith("vcode.ques")){
//            filterChain.doFilter(servletRequest, servletResponse);
//            return;
//        }
//
//        Object o=request.getSession().getAttribute("USER_LOGIN");
//        Object o2=request.getSession().getAttribute("STUDENT_LOGIN");
//        //两个都是空，肯定不能放行
//        if(o==null&&o2==null){
//            request.setAttribute("msg","您还没有登录，不能访问："+ request.getServletPath());
//            request.getRequestDispatcher("/studentlogin.jsp").forward(servletRequest, servletResponse);
//            return;
//        }
//        //第一个为空，不能访问后台功能
//        if(o==null){
//            //更多的地址再加
//            if(path.endsWith(".ques")||path.endsWith(".admin")){
//                request.setAttribute("msg","您还没有登录，不能访问："+ request.getServletPath());
//                request.getRequestDispatcher("/studentlogin.jsp").forward(servletRequest, servletResponse);
//                return;
//            }
//        }
//        if(path.endsWith(".stu")){
//            if(o2==null){
//                request.setAttribute("msg","您还没有登录，不能访问："+ request.getServletPath());
//                request.getRequestDispatcher("/studentlogin.jsp").forward(servletRequest, servletResponse);
//                return;
//            }
//        }
//        filterChain.doFilter(servletRequest, servletResponse);
//    }
//
//    @Override
//    public void destroy() {
//
//    }
//}
